package com.hjs.servlet.regularinspection.regularinspection;

import com.hjs.mapper.RegularInspectionMapper;
import com.hjs.tools.Mapper;
import com.hjs.tools.RequestUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/RegularInspection/delete")
@Slf4j
public class DeleteRegularInspection extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) {
        /**
         * 提供参数
         * regularInspectionID
         */
        RequestUtil requestUtil = new RequestUtil(request, response);
        Mapper<RegularInspectionMapper> regularInspectionMapperMapper = new Mapper<>(RegularInspectionMapper.class);
        try (SqlSession sqlSession = Mapper.getSqlSession()) {
            RegularInspectionMapper regularInspectionMapper = sqlSession.getMapper(RegularInspectionMapper.class);
            boolean sqlResult = regularInspectionMapper.deleteOneRegularInspectionById(requestUtil.getInt("regularInspectionID"));
            Mapper.SessionEnd(sqlResult, sqlSession,"删除定期检测失败");
            requestUtil.responseIsSuccess(sqlResult,"删除失败");
        } catch (Exception e) {
            log.error(e.toString());
            requestUtil.responseFail("已生成年报表的定期检测不允许删除！");
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
        doPost(request,response);
    }
}
